class OidsController < ApplicationController
  before_filter :authenticate_user!

  def activate
    @oid = Oid.find(params[:id])
    @oid.activate
    sleep 1
    flash[:notice] = @oid.active? ? "Activated!" : "Can't monitoring this OID. Help me."
    redirect_to :back
  end

  def deactivate
    @oid = Oid.find(params[:id])
    @oid.deactivate
    flash[:notice] = "deactivated!"
    redirect_to :back
  end

  def new
	  raise "Can't create oid without host id" unless params[:host_id]
    @oid = Oid.new
    @host = Host.find(params[:host_id])
  end

  def edit
    @oid = Oid.find(params[:id])
  end

  def create
    @oid = Oid.new(params[:oid])
    dest_page = @oid.save ? edit_host_path(params[:oid][:host_id])	: :back
    flash[:notice] = "Oid created"
    redirect_to dest_page
  end

  def update
    @oid = Oid.find(params[:id])
    @oid.update_attributes(params[:oid])
    flash[:notice] = "Oid updated"
    redirect_to :back
  end

  def destroy
    @oid = Oid.find(params[:id])
    flash[:notice] = "Oid destroied"
    @oid.destroy
    redirect_to :back
  end
end
